<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>嵌套数组生成器</title>
</head>
<body>
  <script>
    // function后跟一个星号会定义一个生成器函数
    // flat：创建一个新的数组，并根据指定深度递归地将所有子数组元素拼接到新的数组中
    // yield：用于暂停和恢复生成器函数
    let res = []
    function* fn(arr) {
      const nums = arr.flat(Infinity)
      for (let item of nums) yield item;
    }
    let gen = fn([[[6]], [1, 3], []])
    for (let i = 1; i <= 3; i++) {
      res.push(gen.next().value)
    }
    console.log(res)
  </script>
</body>
</html>